package dao.impl;

import dao.UserDao;
import domain.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import utils.C3P0Utils;

import java.sql.SQLException;

/**
 * @Author admin
 * @Date 2019/3/4 9:22
 */
//dao测试成功
public class UserDaoimpl implements UserDao {
    //参数是数据源（连接池），而不是连接对象
    QueryRunner runner = new QueryRunner(C3P0Utils.getDataSource());
    @Override
    public User findByUsernameAndPasswrod(String username, String password) {

        String sql = "SELECT * FROM USER WHERE username = ? AND PASSWORD = ?";
        try {
            return runner.query(sql,new BeanHandler<User>(User.class),username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
